package com.yyk.yykywd.mvvm.ui

import androidx.lifecycle.Observer
import com.yyk.yykywd.ID
import com.yyk.yykywd.R
import com.yyk.yykywd.base.BaseActivity
import com.yyk.yykywd.getTextString
import com.yyk.yykywd.getViewModel
import com.yyk.yykywd.mvvm.view_model.MeetingEndViewModel
import com.yyk.yykywd.util.ToastUtil
import kotlinx.android.synthetic.main.activity_meeting_end.*
import kotlinx.android.synthetic.main.rl_bottom.*

class MeetingEndActivity : BaseActivity() {
    private lateinit var viewModel: MeetingEndViewModel

    override fun initView() {
        setBackArrow()
        setTitle(R.string.meeting_end)
        tv_execute.text = getString(R.string.meeting_end)
        viewModel = getViewModel(this,MeetingEndViewModel::class.java)
        viewModel.id = intent.getStringExtra(ID)
    }

    override fun setListener() {
        tv_execute.setOnClickListener {
            val money = getTextString(et_return_money_num)
            val num = getTextString(tv_attendance)
            val summary = getTextString(et_meeting_summary)
            if (num.isBlank()) {
                ToastUtil.showShort("请填写参会人数")
                return@setOnClickListener
            }
            if (summary.isBlank()) {
                ToastUtil.showShort("请填写会议总结")
                return@setOnClickListener
            }
            viewModel.endMeeting(money,
                    num,
                    summary)
        }

        viewModel.base.observe(this, Observer {
            ToastUtil.showShort(it.msg)
            if (it.code == 200) {
                finish()
            }
        })
    }

    override fun initData() {
    }


    override fun getLayoutId(): Int {
        return  R.layout.activity_meeting_end
    }

}
